import React, { Component } from "react";
// 引入prop-types，用于做props的类型检查
// import PropTypes from "prop-types";
import { string, number, oneOf } from "prop-types";

class Child extends Component {
  static propTypes = {
    name: string.isRequired,
    age: number,
    sex: oneOf(["1", "2"]),
  };
  render() {
    const { name, age, sex } = this.props;
    return (
      <div>
        child组件 - {name} - {age} - {sex}
      </div>
    );
  }
}
// 组件.propTypes是一个固定写法
// Child.propTypes = {
//   name: PropTypes.string,
//   age: PropTypes.number,
// };

class App extends Component {
  render() {
    return (
      <>
        <h2>props的类型检查</h2>
        <Child name="zhangsan" age={20} sex="2" />
      </>
    );
  }
}

export default App;
